package com.tianbo.elfii.client.common;

import java.io.File;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Timer;
import java.util.TimerTask;
import java.util.Vector;
import com.savantbelle.elfiiApi;
import com.tianbo.elfii.client.common.ElfiiCommonConfigNetWifi.ApPanel;
import com.tianbo.elfii.client.common.ElfiiCommonConfigNetWifi.ItemButtonPanel;

public class ElfiiCommonConfigUtil {

	public static elfiiApi api;
	
	public static boolean isNoNetPop = true;
	
	public static boolean isCheckingNet = true;

	public static boolean isValid = true;
	// 自动更新
	public static boolean isAutoUpdated = false;

	// wifi
	public static Map<String, WlanAP> searchedApList = new HashMap<String, WlanAP>();
	public static Map<String, WlanAP> savedApList = new HashMap<String, WlanAP>();
	public static WlanAP curConnectedAp = null;

	public static boolean isWlanOpened = false;

	public static boolean isWlanAutoIP = true;

	public static IPInfo wlanStaticIP = new IPInfo();
	public static IPInfo wlanAutoIP = new IPInfo();

	// lan

	public static boolean isLanAutoIP = true;

	public static IPInfo lanStaticIP = new IPInfo();
	public static IPInfo lanAutoIP = new IPInfo();

	// audio
	public static boolean isAudioEffectOn = false;
	public static int soundVolume = 50;

	// brightness
	public static int brightness = 8;
	
	//productSN
	public static String productSN = "";
	
	
	public static ElfiiCommonRunInfo runInfo;
	
	public static String lanName = "eth0";
	
	public static String wlanName = "eth1";//"wlan2";
	
	public static int productSNLength = 12;
	
	public static String swVersion = "1.0.0";
	
	public static boolean uploadMark=false;
	public static boolean downloadMark=false;
	
	public static char[] chs = {  
        '0','1','2','3','4','5','6','7','8','9',
        'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'  
      };

	public static void init(ElfiiCommonRunInfo runInfo2) {
		runInfo = runInfo2;
		api = new elfiiApi();
		
        Statement st;
        ResultSet rs;
        String str;

        try {
            st = runInfo.getStatement1();
            str="select isaudioeffect,volume,brightness,wifi,autolan,autowlan,encryptedcode,autoupdate,staticlanip,staticlanmask,staticlanrouter,staticlandns1,staticlandns2,staticwlanip,staticwlanmask,staticwlanrouter,staticwlandns1,staticwlandns2,productSN from systemconfig where id='0' " ;

            rs=st.executeQuery(str);
            while(rs.next()){
            	
            	isAudioEffectOn=rs.getBoolean("isaudioeffect");
            	
            	soundVolume=rs.getInt("volume");
            	
                brightness=rs.getInt("brightness");
               
                isWlanOpened = rs.getBoolean("wifi");
                
                isLanAutoIP = rs.getBoolean("autolan");
                
                isWlanAutoIP = rs.getBoolean("autowlan");
                
                isAutoUpdated = rs.getBoolean("autoUpdate");
                
                lanStaticIP.ip = rs.getString("staticlanip");
                lanStaticIP.netmask = rs.getString("staticlanmask");
                lanStaticIP.router = rs.getString("staticlanrouter");
                lanStaticIP.dns1 = rs.getString("staticlandns1");
                lanStaticIP.dns2 = rs.getString("staticlandns2");
                
                wlanStaticIP.ip = rs.getString("staticwlanip");
                wlanStaticIP.netmask = rs.getString("staticwlanmask");
                wlanStaticIP.router = rs.getString("staticwlanrouter");
                wlanStaticIP.dns1 = rs.getString("staticwlandns1");
                wlanStaticIP.dns2 = rs.getString("staticwlandns2");
                
                String encryptedCode = rs.getString("encryptedcode");
                
                String src="";
                
                try{
                	src = api.getSN(lanName);
                }
                catch(Exception e){
                	
                }
                
                if(encryptedCode.equals("") && !src.equals("")){
                	Statement st2 = runInfo.getStatement2();
                	String str2 = "UPDATE systemconfig SET encryptedcode='"+api.enCodePrdSn(src)+"' WHERE id='0'";
                	st2.execute(str2);
                }
                else{
                	if(!api.doValidateProduct(src, encryptedCode) || src.equals("")){
                		System.out.println("Invalid Version");
                		isValid = false;
                		return;
                	}
                }
                
                String savedSN = rs.getString("productSN");
                
                productSN = api.getBIOSSn();
                
                productSN = productSN.substring(0, productSNLength);
                
                boolean isProductSNValid = checkProductSNValidation(productSN);
                
                if(!savedSN.startsWith("TMP") && !isProductSNValid){
                	productSN="TMP";
                	for(int i=0;i<productSNLength-3;i++){
                		productSN+=chs[(int) (Math.random()*36)];
                	}
                	Statement st2 = runInfo.getStatement2();
                	String str2 = "UPDATE systemconfig SET productSN='"+productSN+"' WHERE id='0'";
                	st2.execute(str2);
                	savedSN = productSN;
                }
              
                else if(isProductSNValid && !savedSN.equals(productSN)){
                	Statement st2 = runInfo.getStatement2();
                	String str2 = "UPDATE systemconfig SET productSN='"+productSN+"' WHERE id='0'";
                	st2.execute(str2);
                	savedSN = productSN;
                }
                
                else{
                	productSN = savedSN;
                }
                
                runInfo.setMachineId(savedSN);
                
            }
            
        } catch (Exception e) {System.out.print("init()  "+e);}
		
	}
	
	public static boolean checkProductSNValidation(String productSN){
		
		for(int i=0;i<productSN.length();i++){
			char c = productSN.charAt(i);
			
			if(!Character.isDigit(c) && (c<'A'||c>'Z')){
				return false;
			}
		}
		return true;
	}
	
	public static String getSwVersion(){
		
        
        Statement st = runInfo.getStatement1();
        String str="select * from gxtxb order by xh desc limit 1";
        
        ResultSet rs;
		try {
			rs = st.executeQuery(str);

	        while(rs.next()){
	        	
	        	swVersion = rs.getString("bbh");
	        	System.out.println(swVersion+" "+rs.getString("bbh"));
	        }
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		return swVersion;
	}

	public static boolean setSoundVolume(int value) {
		boolean ret = false;

		if (value > 100)
			value = 100;

		if (value < 0)
			value = 0;

		if (api.setSoundVolume(String.valueOf(value))) {
			soundVolume = value;
			ret = true;
		}
		
		String str = "UPDATE systemconfig SET volume = "+soundVolume+ " WHERE id = '0'";
        Statement st = runInfo.getStatement1();
        try {
			st.execute(str);
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		return ret;
	}

	public static int getSoundVolume() {
		return soundVolume;
	}

//	public static boolean setSoundMute(boolean flag) {
//		boolean ret = false;
//		if (api.setSoundMute(flag)) {
//			isMute = flag;
//			ret = true;
//		}
//
//		return ret;
//	}
//
//	public static boolean setSoundMuteSts() {
//		return isMute;
//	}

	public static boolean setBrightness(int value) {
		boolean ret = false;

		if (value > 15)
			value = 15;

		if (value < 0)
			value = 0;

		if (api.setBrightness(String.valueOf(value))) {
			brightness = value;
			ret = true;
		}
		
		String str = "UPDATE systemconfig SET brightness = "+brightness+ " WHERE id = '0'";
        Statement st = runInfo.getStatement1();
        try {
			st.execute(str);
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		return ret;
	}

	public static int getBrightness() {
		return brightness;
	}

	public static String getProductSN() {
		return productSN;
	}

	public static String getWlanSN() {

		String sn = api.getSN(wlanName);
		
		sn = sn.toUpperCase();
		
		String ret=sn.substring(0, 2);
		
		for(int i=1;i<6;i++){

			ret += ":";
			ret += sn.substring(2*i, 2*i+2);
		}
		
		return ret;
	}

	public static String getLanSN() {
		String sn = api.getSN(lanName);
		
		sn = sn.toUpperCase();
		
		String ret=sn.substring(0, 2);
		
		for(int i=1;i<6;i++){

			ret += ":";
			ret += sn.substring(2*i, 2*i+2);
		}
		
		return ret;
	}
	
	public static void setAutoUpdated(boolean flag) {
		isAutoUpdated = flag;
	
		ElfiiCommonConfigUtil.downloadMark = isAutoUpdated;
		
		int para = 0;
		
		if(isAutoUpdated){
			para = 1;
			ElfiiCommonConfigUtil.startUpAndDownload();
		}
		
		
		String str = "UPDATE systemconfig SET autoupdate = "+para+ " WHERE id = '0'";
        Statement st = runInfo.getStatement1();
        try {
			st.execute(str);
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	public static void setWlanOpened(boolean flag) {
		isWlanOpened = flag;
		
		int para = 0;
		
		if(isWlanOpened){
			para = 1;
		}
		
		api.setWLANSts(isWlanOpened);
		
		String str = "UPDATE systemconfig SET wifi = "+para+ " WHERE id = '0'";
        Statement st = runInfo.getStatement1();
        try {
			st.execute(str);
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	public static void setWlanAutoIP(boolean flag) {
		isWlanAutoIP = flag;
		
		int para = 0;
		
		if(isWlanAutoIP){
			para = 1;
		}
		
		String str = "UPDATE systemconfig SET autowlan = "+para+ " WHERE id = '0'";
        Statement st = runInfo.getStatement1();
        try {
			st.execute(str);
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	public static void saveWlanStaticIP(){
		String str = "UPDATE systemconfig SET staticwlanip='"+wlanStaticIP.ip+"', staticwlanmask='"+wlanStaticIP.netmask+"', staticwlanrouter='"+wlanStaticIP.router+"', staticwlandns1='"+wlanStaticIP.dns1+"', staticwlandns2='"+wlanStaticIP.dns2+ "' WHERE id = '0'";
        Statement st = runInfo.getStatement1();
        try {
			st.execute(str);
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	public static void setLanAutoIP(boolean flag) {
		isLanAutoIP = flag;
		
		int para = 0;
		
		if(isLanAutoIP){
			para = 1;
		}
		
		String str = "UPDATE systemconfig SET autolan = "+para+ " WHERE id = '0'";
//       System.out.println(str);
		Statement st = runInfo.getStatement1();
        try {
			st.execute(str);
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	public static void saveLanStaticIP(){
		String str = "UPDATE systemconfig SET staticlanip='"+lanStaticIP.ip+"', staticlanmask='"+lanStaticIP.netmask+"', staticlanrouter='"+lanStaticIP.router+"', staticlandns1='"+lanStaticIP.dns1+"', staticlandns2='"+lanStaticIP.dns2+ "' WHERE id = '0'";
        Statement st = runInfo.getStatement1();
        try {
			st.execute(str);
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	public static void scanSearchedWlan() {
		searchedApList.clear();

		String retStr = api.scanWLAN();
		
		if(retStr.equals(""))
			return;
		
		List<String> apItems = Arrays.asList(retStr.split("\\s*  ,  \\s*"));

		for (int i = 0; i < apItems.size(); i++) {
			
			List<String> infoItems =  Arrays.asList(apItems.get(i).split("\\s* , \\s*"));
			
			int quality = 0;
			
			try{
				quality = Integer.parseInt(infoItems.get(1));
			}
			catch(Exception e){
				continue;
			}
			
			WlanAP ap = new WlanAP();
			ap.setSSID(infoItems.get(0));
			ap.setQuality(quality);
			ap.setCurStat(APSTAT.UNCONNECTED);

			if (infoItems.get(2).equals("--")) {
				ap.setEncryptedStat(false);
			} else {
				ap.setEncryptedStat(true);
				
				String encryptType = "0";
				
				if(infoItems.get(2).contains("WEP")){
					encryptType = "2";
				}
				else if(infoItems.get(2).contains("WPA")){
					encryptType = "5";
				}
				
				ap.setEncryptType(encryptType);
			}
			
			System.out.println("Searched AP "+ap.getSSID()+" "+ap.getEncryptType());
			
			searchedApList.put(ap.getSSID(), ap);
		}	
		lookForConnectedAp();
	}

	public static void scanSavedWlan() {
		savedApList.clear();

		if (new File("/home/SVWLAN").exists() == false)
			return;

		String ssids[] = api.getWLAN_ALL_Profile();

		if (ssids.length == 0)
			return;
		
		for (int i = 0; i < ssids.length; i++) {
			String apInfoStrs[] = api.getWLAN_Profile(ssids[i]);
			
			if(apInfoStrs.length !=11 || apInfoStrs[1].equals(""))
				return;
			
			WlanAP ap = new WlanAP();
			
			ap.setEncryptType(apInfoStrs[0]);
			
			ap.setSSID(apInfoStrs[1]);
																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																						
			if (apInfoStrs[2].equals("")) {
				ap.setEncryptedStat(false);
			} else {
				ap.setEncryptedStat(true);
				ap.setPassword(apInfoStrs[2]);
			}
			
			if(apInfoStrs[9].equals("1")){
				ap.setHiddenStat(true);
			}
			else{
				ap.setHiddenStat(false);
			}

			ap.setSavedStat(true);

			savedApList.put(ap.getSSID(), ap);
		}
	}

	public static void lookForConnectedAp() {
		
		curConnectedAp = null;
		
		String retStr = api.getWLAN(wlanName);

		System.out.println("connected "+retStr);
		
		if (retStr.equals(""))
			return;

		String apInfoStrs[] = retStr.split(",");

		if (apInfoStrs.length < 4 || apInfoStrs[0].trim().equals(""))
			return;
		
		curConnectedAp = new WlanAP();

		curConnectedAp.setSSID(apInfoStrs[0].trim());

		if (apInfoStrs[1].equals("")) {
			curConnectedAp.setEncryptedStat(false);
			curConnectedAp.setPassword("");
		} else {
			curConnectedAp.setEncryptedStat(true);
			curConnectedAp.setPassword(apInfoStrs[1].trim());
		}

//		if(checkNetConnected(10,5)>0){
//			curConnectedAp.setCurStat(APSTAT.NOSERVICE);
//		}
//		else{
			curConnectedAp.setCurStat(APSTAT.CONNECTED);
//		}
			
		IPInfo tmpIpInfo = new IPInfo();

		tmpIpInfo.ip = apInfoStrs[3].trim();
		tmpIpInfo.router = apInfoStrs[4].trim();

		int maskInt = Integer.parseInt(apInfoStrs[5].trim());
		String maskStr = "255.255.255.255";
		switch (maskInt % 8) {
		case 0:
			maskStr = "0.0.0.0";
			break;
		case 1:
			maskStr = "255.0.0.0";
			break;
		case 2:
			maskStr = "255.255.0.0";
			break;
		case 3:
			maskStr = "255.255.255.0";
			break;
		default:
			break;
		}
		tmpIpInfo.router = maskStr;

		if (apInfoStrs[2].trim().equals("On")) {
			isWlanAutoIP = true;
			wlanAutoIP = tmpIpInfo;
		} else {
			isWlanAutoIP = false;
		}

	}

	public static int connectWlan(WlanAP ap, String resultStr) {

//		api.delWLAN_Profile(ssid);
		
		String connectCMD[] = new String[11];// = ssid + "," + password + ",";
		
		connectCMD[0] = ap.getEncryptType();
		connectCMD[1] = ap.getSSID();
		connectCMD[2] = ap.getPassword();
		connectCMD[3] = "";
		connectCMD[4] = "";
		connectCMD[5] = "";
		connectCMD[6] = "";
		connectCMD[7] = "";
		connectCMD[8] = "";
		
		if(ap.getHiddenStat()){
			connectCMD[9] = "1";
		}
		else{
			connectCMD[9] = "0";
		}
		
		connectCMD[10] = "1";
		
		if (isWlanAutoIP) {
			connectCMD[3] = "1";
		} else {
			String netmask = api.netmask2cidr(wlanStaticIP.netmask);
			connectCMD[3] = "0";
			connectCMD[4] = wlanStaticIP.ip;
			connectCMD[5] = wlanStaticIP.router;
			connectCMD[6] = netmask;
			connectCMD[7] = wlanStaticIP.dns1;
			connectCMD[8] = wlanStaticIP.dns2;
		}

		disConnectWlan();
		
		System.out.println("disConnectWlan "+ElfiiCommonUtil.getLocalCurrentTime(""));

		ElfiiCommonConfigUtil.scanSearchedWlan();
		try {
			Thread.sleep(4000);
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		api.delWLAN_Profile(ap.getSSID());
		
		System.out.println("ConnectWlan "+connectCMD[1]+" "+connectCMD[3]+" "+connectCMD[9]);
		
		
		if(isWlanAutoIP && !ap.getHiddenStat()){
			resultStr = api.setWLAN_Auto(connectCMD);
		}
		else{
			resultStr = api.setWLAN_Manual(connectCMD);
		}
		
		System.out.println("resultStr "+resultStr);
		api.addWLAN_Profile(connectCMD);

		String tokens[] = resultStr.split(",");

		int ret = 4;

		if (tokens.length > 1) {
			if (tokens[0].equals("0")) {
				ret = 0;
			} else if (tokens[0].equals("1")) {
				ret = 1;
			} else if (tokens[0].equals("2")) {
				ret = 2;
			} else if (tokens[0].equals("3")) {
				ret = 3;
			}

			resultStr = tokens[1];
		}
		return ret;
	}
	
	public static void disConnectWlan(){
		boolean ret = doRootCmd("rm -rf /etc/NetworkManager/system-connections/*");
		
	}

	public static boolean connectLan() {
		
		if(api.getLAN(lanName).equals(""))
			return false;
			
		String cmdStr = "";
		if(isLanAutoIP){
			cmdStr = "On,,,,,";
		}
		else{
			cmdStr = "Off,"+lanStaticIP.ip+","+lanStaticIP.router+","+api.netmask2cidr(lanStaticIP.netmask)+","+lanStaticIP.dns1+","+lanStaticIP.dns2;
		}
	
		return api.setLAN(lanName, cmdStr);
	}
	
	/**
	 * @return
	 */
	/**
	 * @return
	 */
	public static int checkNetConnected(int time, int times){
		if(getLanConnectedStat() && getWlanConnectedStat()){
			return -1;
		}
		else{
			
			String pingRet = api.chkInternet("113.11.197.68", String.valueOf(time), String.valueOf(time));
//			System.out.println("ping "+pingRet);
			if(pingRet.equals("") || pingRet.equals("+3") ){
				return 1;
			}
			
			if(Integer.parseInt(pingRet.substring(0,pingRet.length()-1))>70){
				return 2;
			}
			
			
			return 0;
		}
	}
	
	public static boolean getLanConnectedStat(){
		if(api.getLAN(lanName).equals("")){
			return false;
		}
		else{
			return true;
		}
	}
	
	public static boolean getWlanConnectedStat(){
		if(api.getWLAN(wlanName).equals(",,")){
			return false;
		}
		else{
			return true;
		}
	}
	
	public static void doCalibration(int type){
		if(type==4){
			api.doCalMonitor("4");
		}
		else{
			api.doCalMonitor("9");
		}
	}
	
	public static boolean doRootCmd(String cmdStr){
		return api.doRootCmd(cmdStr);
	}
	
    public static void startUpAndDownload(){
        UpAndDownloadThread upAndDownloadThread = new UpAndDownloadThread();
        upAndDownloadThread.setRunInfo(runInfo);
        upAndDownloadThread.start();
    }

}

class WlanConnectingThread extends Thread {
	ElfiiCommonConfigNetWifi wifiConfig;
	WlanAP ap;
	ItemButtonPanel apPanel;
	Timer timer;

	boolean isStop = false;

	public WlanConnectingThread(ElfiiCommonConfigNetWifi wifiConfig) {

		this.ap = wifiConfig.selectedApPanel.ap;
		apPanel = wifiConfig.selectedApPanel;
		this.wifiConfig = wifiConfig;
		timer = new Timer();

		if (wifiConfig.connectedApPanel != null) {
			if(ap.getSavedStat()){
				wifiConfig.connectedApPanel.str2 = "已保存";
				wifiConfig.connectedApPanel.ap.setCurStat(APSTAT.SAVED);
			}
			else{
				wifiConfig.connectedApPanel.str2 = "未连接";
				wifiConfig.connectedApPanel.ap.setCurStat(APSTAT.UNCONNECTED);
			}

			wifiConfig.connectedApPanel.repaint();
			
			wifiConfig.connectedApPanel = null;
			
			ElfiiCommonConfigUtil.curConnectedAp = null;
		}
		ElfiiCommonConfigUtil.wlanAutoIP.setToDefault();
	}

	public void run() {
//		wifiConfig.paintApPanelList();
		timer.schedule(new MyTask(), 500, 500);


		System.out.println("Try to connect "+ap.getSSID());
		System.out.println("start " + ap.getSSID()+" "+ap.getPassword()+" "+ElfiiCommonUtil.getLocalCurrentTime(""));
		ap.connect();
		System.out.println("stop " + ap.getSSID()+" "+ElfiiCommonUtil.getLocalCurrentTime(""));
		isStop = true;
	}

	public void cancel() {
		if (timer != null)
			timer.cancel();
		System.out.println("cancel " + ap.getSSID());

		this.stop();
	}

	class MyTask extends TimerTask {
		int count = 0;

		@Override
		public void run() {

			if (isStop) {

				if (ap.connectRetFlag == 0) {

					ElfiiCommonConfigUtil.lookForConnectedAp();

					if (ElfiiCommonConfigUtil.curConnectedAp == null) {
						System.out.println("connected=null ");// isStop;
					} else {
			
						apPanel.str2 = "已连接";
						ap.setCurStat(APSTAT.CONNECTED);
						
						if(ElfiiCommonConfigUtil.downloadMark){
							ElfiiCommonConfigUtil.startUpAndDownload();
						}
						
						if(ap.isCustomed){
							apPanel.str2 = "";
							ap = null;			
						}
						System.out.println("connected ok "+ap.getSSID());
						apPanel.repaint();

						wifiConfig.setWifiListPane();
						wifiConfig.mainPanel.repaint();

						timer.cancel();
						return;
					}
				} else {
					
					
					if(ap.isCustomed){
						apPanel.str2 = "";
						apPanel.repaint();
						
						wifiConfig.showCustomDialogPane();
					}
					else{
						if(apPanel.ap.getSavedStat()){
							apPanel.str2 = "已保存";
						}
						else{
							apPanel.str2 = "未连接";
						}
						apPanel.repaint();
						
						wifiConfig.showDialogPane();
					}
					timer.cancel();
					return;
				}
			}
			
			if(ap.isCustomed){
				apPanel.str2= ap.getSSID()+" ";
			}
			else{
				apPanel.str2 = "";
			}

			switch (count % 3) {
			case 0:
				apPanel.str2 += "正在连接.";
				break;
			case 1:
				apPanel.str2 += "正在连接..";
				break;
			case 2:
				apPanel.str2 += "正在连接...";
				break;
			}

			apPanel.repaint();
			count++;
		}

	}
}

class IPInfo {
	public String ip = "0.0.0.0";
	public String netmask = "255.255.255.0";
	public String router = "0.0.0.0";
	public String dns1 = "0.0.0.0";
	public String dns2 = "0.0.0.0";

	public void clear() {
		ip = "";
		netmask = "";
		router = "";
		dns1 = "";
		dns2 = "";
	}

	public void setToDefault() {
		ip = "0.0.0.0";
		netmask = "255.255.255.0";
		router = "0.0.0.0";
		dns1 = "0.0.0.0";
		dns2 = "0.0.0.0";
	}
	
	public boolean equals(IPInfo info){
		if(ip.equals(info.ip) && netmask.equals(info.netmask) && router.equals(info.router) && dns1.equals(info.dns1) && dns2.equals(info.dns2)){
			return true;
		}
		
		return false;
	}

}

class APSTAT {
	public static int CONNECTED = 0;
	public static int UNCONNECTED = 1;
	public static int NOSERVICE = 2;
	public static int SAVED = 3;
	public static int CONNECTING = 4;
}

class WlanAP {
	private String ssid = "";
	private int quality = 0;
	private boolean isEncrypted = false;
	private String password = "";
	private boolean isSaved = false;
	
	private boolean isHidden = false;
	
	private String encryptType="";

	private int curStat = APSTAT.UNCONNECTED;

	public int connectRetFlag = -1;
	public String connectRetStr = "";
	
	public boolean isCustomed = false;

	public WlanAP() {

	}

	public String getSSID() {
		return ssid;
	}

	public void setSSID(String ssid) {
		this.ssid = ssid;
	}

	public int getQuality() {
		return quality;
	}

	public void setQuality(int quality) {
		this.quality = quality;
	}

	public boolean getEncryptedStat() {
		return isEncrypted;
	}

	public void setEncryptedStat(boolean isEncrypted) {
		this.isEncrypted = isEncrypted;
	}
	
	public String getEncryptType() {
		return encryptType;
	}

	public void setEncryptType(String encryptType) {
		this.encryptType = encryptType;
	}

	public boolean getSavedStat() {
		return isSaved;
	}

	public void setSavedStat(boolean isSaved) {
		this.isSaved = isSaved;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public int getCurStat() {
		return curStat;
	}

	public void setCurStat(int curStat) {
		this.curStat = curStat;
	}
	
	public boolean getHiddenStat(){
		return isHidden;
	}
	
	public void setHiddenStat(boolean hiddenStat){
		isHidden = hiddenStat;
	}

	public void connect() {
		if (connectRetFlag == -1) {
			connectRetFlag = ElfiiCommonConfigUtil.connectWlan(this, connectRetStr);
		}
	}

	public void disconnect() {
		if (connectRetFlag != -1) {
			ElfiiCommonConfigUtil.wlanAutoIP.setToDefault();
			connectRetFlag = -1;
		}
	}
	
	
}